package com.abbas.CayTcore

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import android.os.Handler
import android.os.Looper
import androidx.room.Room
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.abbas.CayTcore.database.CoreDataBase
import java.text.SimpleDateFormat
import java.util.*


class CoreApp : Application() {

    init {
        //staticInit()
    }

    override fun onCreate() {
        super.onCreate()

        context = this
        sp = getSharedPreferences("sp", Context.MODE_PRIVATE)
    }

    companion object {
        @SuppressLint("StaticFieldLeak")
        lateinit var context: Context
        val handler: Handler = Handler(Looper.getMainLooper())
        lateinit var sp: SharedPreferences
        val dateStr = SimpleDateFormat.getDateInstance()
            .format(Date())

        val migration = object : Migration(1, 2) {
            override fun migrate(database: SupportSQLiteDatabase) {
                database.execSQL(
                    ""
                )
            }

        }
        val db: CoreDataBase by lazy {
            Room.databaseBuilder(
                context!!,
                CoreDataBase::class.java,
                "core_database"
            )
                .fallbackToDestructiveMigration()
                .build()
        }

//        fun staticInit() {
//            //设置全局的Header构建器
//            //设置全局的Header构建器
//            SmartRefreshLayout.setDefaultRefreshHeaderCreator(DefaultRefreshHeaderCreator { context, layout ->
//                layout.setPrimaryColorsId(R.color.background_light, R.color.white) //全局设置主题颜色
//                ClassicsHeader(context) //.setTimeFormat(new DynamicTimeFormat("更新于 %s"));//指定为经典Header，默认是 贝塞尔雷达Header
//            })
            //设置全局的Footer构建器
            //设置全局的Footer构建器
//            SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout -> //指定为经典Footer，默认是 BallPulseFooter
//                ClassicsFooter(context).setDrawableSize(20)
//            }
//        }
    }


}